import service from "../../utils/request.ts";
import type {AxiosPromise} from "axios";

/**
 * 分页查询租户信息列表
 * @param payload 分页参数
 */
export const getExamPage = (payload): AxiosPromise<any[]> => {
    return service({
        url: "/exam/page",
        method: 'POST',
        data: payload
    })
}

export const addExamBase = (payload): AxiosPromise<any[]> => {
    return service({
        url: "/exam/save",
        method: 'POST',
        data: payload
    })
}

export const update = (payload): AxiosPromise<any[]> => {
    return service({
        url: "/exam/update",
        method: 'put',
        data: payload
    })
}
export const getExamBaseInfo = (id)=> {
    return service({
        url: `/exam/${id}`,
        method: 'get',
        data: null
    })
}
export const getExamQuestion = (id)=> {
    return service({
        url: `/exam/${id}/question`,
        method: 'get',
        data: null
    })
}
export const addQuestionToExam = (question)=> {
    return service({
        url: `/exam/question`,
        method: 'post',
        data: question
    })
}
export const removeExamQuestionApi = (question)=> {
    return service({
        url: `/exam/question/remove`,
        method: 'delete',
        data: question
    })
}
/**
 * 添加考试人员
 * @param examId
 * @param data
 */
export const addExamUserApi = (examId,data)=> {
    return service({
        url: `/exam/${examId}/user`,
        method: 'post',
        data: data
    })
}


/**
 * 发布考试
 */
export const publishExam = (data)=> {
    return service({
        url: `/exam/publish`,
        method: 'put',
        data: data
    })
}

export const userExamList = (page,pageSize,status,examName)=> {
    return service({
        url: `/student/exam/page`,
        method: 'get',
        params:{page:page,pageSize:pageSize,status:status,examName:examName},
        data: null
    })
}

export const getExamQuestionId = (examId)=> {
    return service({
        url: `/student/exam/question`,
        method: 'get',
        params:{examId:examId},
        data: null
    })
}
export const getCurrentExamQuestion = (examId,questionId)=> {
    return service({
        url: `/student/exam/question/current`,
        method: 'get',
        params:{examId:examId,questionId:questionId},
        data: null
    })
}
export const saveExamAnswer = (data)=> {
    return service({
        url: `/student/exam/question/save`,
        method: 'post',
        data: data
    })
}
export const checkSubmit = (examId)=> {
    return service({
        url: `/student/exam/question/check`,
        method: 'get',
        params:{examId:examId},
        data: null
    })
}
export const submit = (examId)=> {
    return service({
        url: `/student/exam/submit`,
        method: 'put',
        params:{examId:examId},
        data: null
    })
}


/**
 * 检查是否已交卷
 * @param examId
 */
export const savePaperCheck = (examId)=> {
    return service({
        url: `/student/exam/checkPaper/${examId}`,
        method: 'get',
        data: null
    })
}
export const saveCorrectInfo = (data)=> {
    return service({
        url: `/exam/correct/init`,
        method: 'post',
        data: data
    })
}

export const getCorrectExamList = (page,pageSize,examName)=> {
    return service({
        url: `/exam/user/correct`,
        method: 'get',
        params:{page:page,pageSize:pageSize,examName:examName},
        data: null
    })
}
export const getQuestionInfo = (examId)=> {
    return service({
        url: `/exam/correct/${examId}`,
        method: 'get',
        data: null
    })
}
export const submitExamQuestionScore = (examId,userId,questionId,score)=> {
    return service({
        url: `/exam/correct/questionScore`,
        method: 'post',
        params:{examId:examId,userId:userId,questionId:questionId,score:score},
        data: null
    })
}
export const exportCertificate = (id)=> {
    return service({
        url: `/exam/exportCertificate/${id}`,
        method: 'get',
        data: null
    })
}
